package com.google.ads.b;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import com.google.ads.as;
import com.google.ads.e;
import com.google.ads.g;
import com.google.ads.util.AdUtil;
import com.google.ads.util.ac;
import com.google.ads.util.d;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public final class t
  implements Runnable
{
  private final j a;
  private final r b;
  private final v c;
  private volatile boolean d;
  private boolean e;
  private String f;
  private Thread g = null;

  t(j paramj, r paramr)
  {
    this(paramj, paramr, new u());
  }

  t(j paramj, r paramr, v paramv)
  {
    this.a = paramj;
    this.b = paramr;
    this.c = paramv;
  }

  private void a(Context paramContext, HttpURLConnection paramHttpURLConnection)
  {
    String str = PreferenceManager.getDefaultSharedPreferences(paramContext).getString("drt", "");
    if ((this.e) && (!TextUtils.isEmpty(str)))
    {
      if (AdUtil.a == 8)
        paramHttpURLConnection.addRequestProperty("X-Afma-drt-Cookie", str);
    }
    else
      return;
    paramHttpURLConnection.addRequestProperty("Cookie", str);
  }

  private void a(HttpURLConnection paramHttpURLConnection)
  {
    b(paramHttpURLConnection);
    f(paramHttpURLConnection);
    g(paramHttpURLConnection);
    h(paramHttpURLConnection);
    e(paramHttpURLConnection);
    i(paramHttpURLConnection);
    j(paramHttpURLConnection);
    k(paramHttpURLConnection);
    d(paramHttpURLConnection);
    c(paramHttpURLConnection);
    l(paramHttpURLConnection);
  }

  private void a(HttpURLConnection paramHttpURLConnection, int paramInt)
  {
    if ((300 <= paramInt) && (paramInt < 400))
    {
      String str2 = paramHttpURLConnection.getHeaderField("Location");
      if (str2 == null)
      {
        d.c("Could not get redirect location from a " + paramInt + " redirect.");
        this.a.a(e.d);
        a();
        return;
      }
      a(paramHttpURLConnection);
      this.f = str2;
      return;
    }
    if (paramInt == 200)
    {
      a(paramHttpURLConnection);
      String str1 = AdUtil.a(new InputStreamReader(paramHttpURLConnection.getInputStream())).trim();
      d.a("Response content is: " + str1);
      if (TextUtils.isEmpty(str1))
      {
        d.a("Response message is null or zero length: " + str1);
        this.a.a(e.b);
        a();
        return;
      }
      this.a.a(str1, this.f);
      a();
      return;
    }
    if (paramInt == 400)
    {
      d.c("Bad request");
      this.a.a(e.a);
      a();
      return;
    }
    d.c("Invalid response code: " + paramInt);
    this.a.a(e.d);
    a();
  }

  private void b()
  {
    while (!this.d)
    {
      URL localURL = new URL(this.f);
      HttpURLConnection localHttpURLConnection = this.c.a(localURL);
      try
      {
        a((Context)this.b.g().f.a(), localHttpURLConnection);
        AdUtil.a(localHttpURLConnection, (Context)this.b.g().f.a());
        localHttpURLConnection.setInstanceFollowRedirects(false);
        localHttpURLConnection.connect();
        a(localHttpURLConnection, localHttpURLConnection.getResponseCode());
        localHttpURLConnection.disconnect();
      }
      finally
      {
        localHttpURLConnection.disconnect();
      }
    }
  }

  private void b(HttpURLConnection paramHttpURLConnection)
  {
    String str = paramHttpURLConnection.getHeaderField("X-Afma-Debug-Dialog");
    if (!TextUtils.isEmpty(str))
      this.a.e(str);
  }

  private void c(HttpURLConnection paramHttpURLConnection)
  {
    String str = paramHttpURLConnection.getHeaderField("Content-Type");
    if (!TextUtils.isEmpty(str))
      this.a.b(str);
  }

  private void d(HttpURLConnection paramHttpURLConnection)
  {
    String str = paramHttpURLConnection.getHeaderField("X-Afma-Mediation");
    if (!TextUtils.isEmpty(str))
      this.a.a(Boolean.valueOf(str).booleanValue());
  }

  private void e(HttpURLConnection paramHttpURLConnection)
  {
    String str = paramHttpURLConnection.getHeaderField("X-Afma-Interstitial-Timeout");
    if (!TextUtils.isEmpty(str));
    try
    {
      float f1 = Float.parseFloat(str);
      this.b.a(()(f1 * 1000.0F));
      return;
    }
    catch (NumberFormatException localNumberFormatException)
    {
      d.d("Could not get timeout value: " + str, localNumberFormatException);
    }
  }

  private void f(HttpURLConnection paramHttpURLConnection)
  {
    String str1 = paramHttpURLConnection.getHeaderField("X-Afma-Tracking-Urls");
    if (!TextUtils.isEmpty(str1))
      for (String str2 : str1.trim().split("\\s+"))
        this.b.b(str2);
  }

  private void g(HttpURLConnection paramHttpURLConnection)
  {
    String str1 = paramHttpURLConnection.getHeaderField("X-Afma-Click-Tracking-Urls");
    if (!TextUtils.isEmpty(str1))
      for (String str2 : str1.trim().split("\\s+"))
        this.a.a(str2);
  }

  private void h(HttpURLConnection paramHttpURLConnection)
  {
    String str = paramHttpURLConnection.getHeaderField("X-Afma-Refresh-Rate");
    if (!TextUtils.isEmpty(str));
    do
      try
      {
        float f1 = Float.parseFloat(str);
        if (f1 > 0.0F)
        {
          this.b.a(f1);
          if (!this.b.q())
            this.b.e();
          return;
        }
      }
      catch (NumberFormatException localNumberFormatException)
      {
        d.d("Could not get refresh value: " + str, localNumberFormatException);
        return;
      }
    while (!this.b.q());
    this.b.d();
  }

  private void i(HttpURLConnection paramHttpURLConnection)
  {
    String str = paramHttpURLConnection.getHeaderField("X-Afma-Orientation");
    if (!TextUtils.isEmpty(str))
    {
      if (!str.equals("portrait"))
        break label36;
      this.a.a(AdUtil.b());
    }
    label36: 
    while (!str.equals("landscape"))
      return;
    this.a.a(AdUtil.a());
  }

  private void j(HttpURLConnection paramHttpURLConnection)
  {
    if (!TextUtils.isEmpty(paramHttpURLConnection.getHeaderField("X-Afma-Doritos-Cache-Life")));
    try
    {
      long l = Long.parseLong(paramHttpURLConnection.getHeaderField("X-Afma-Doritos-Cache-Life"));
      this.b.b(l);
      return;
    }
    catch (NumberFormatException localNumberFormatException)
    {
      d.e("Got bad value of Doritos cookie cache life from header: " + paramHttpURLConnection.getHeaderField("X-Afma-Doritos-Cache-Life") + ". Using default value instead.");
    }
  }

  private void k(HttpURLConnection paramHttpURLConnection)
  {
    String str = paramHttpURLConnection.getHeaderField("Cache-Control");
    if (!TextUtils.isEmpty(str))
      this.a.c(str);
  }

  private void l(HttpURLConnection paramHttpURLConnection)
  {
    String str = paramHttpURLConnection.getHeaderField("X-Afma-Ad-Size");
    if (!TextUtils.isEmpty(str))
      try
      {
        String[] arrayOfString = str.split("x", 2);
        if (arrayOfString.length != 2)
        {
          d.e("Could not parse size header: " + str);
          return;
        }
        int i = Integer.parseInt(arrayOfString[0]);
        int j = Integer.parseInt(arrayOfString[1]);
        this.a.a(new g(i, j));
        return;
      }
      catch (NumberFormatException localNumberFormatException)
      {
        d.e("Could not parse size header: " + str);
      }
  }

  void a()
  {
    this.d = true;
  }

  void a(String paramString)
  {
    try
    {
      if (this.g == null)
      {
        this.f = paramString;
        this.d = false;
        this.g = new Thread(this);
        this.g.start();
      }
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  public void a(boolean paramBoolean)
  {
    this.e = paramBoolean;
  }

  public void run()
  {
    try
    {
      b();
      return;
    }
    catch (MalformedURLException localMalformedURLException)
    {
      d.b("Received malformed ad url from javascript.", localMalformedURLException);
      this.a.a(e.d);
      return;
    }
    catch (IOException localIOException)
    {
      d.d("IOException connecting to ad url.", localIOException);
      this.a.a(e.c);
      return;
    }
    catch (Throwable localThrowable)
    {
      d.b("An unknown error occurred in AdResponseLoader.", localThrowable);
      this.a.a(e.d);
    }
  }
}

/* Location:           D:\Studium\Bachelorarbeit\BA Marcus Wobig\BA\BA\Decompiler\PicturePassword APK\Programm\PicturePassword_dex2jar.jar
 * Qualified Name:     com.google.ads.b.t
 * JD-Core Version:    0.6.2
 */